home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 37 / IOPROG_37.ISO / SOFT / Multilizer.exe / disk1 / data1.cab / data1 / [Group19]VCL Source Professional / Ivloseld.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-08-31  |  3.7 KB  |  168 lines

  1. unit IvLoSelD;
  2.  
  3. {$I IVMULTI.INC}
  4.  
  5. interface
  6.  
  7. uses
  8. {$IFDEF WIN32}
  9.   Windows,
  10. {$ELSE}
  11.   WinTypes, WinProcs,
  12. {$ENDIF}
  13.   Classes, Graphics, Forms, Controls, Buttons, StdCtrls,
  14.   IvDictio, IvMlCtrl, IvMulti;
  15.  
  16. type
  17.   TIvLocaleSelectDialog = class(TForm)
  18.     ListBox: TIvListBox;
  19.     CancelButton: TButton;
  20.     OkButton: TButton;
  21.     HelpButton: TButton;
  22.     Translator: TIvTranslator;
  23.     procedure ListBoxDblClick(Sender: TObject);
  24.     procedure HelpButtonClick(Sender: TObject);
  25.  
  26.   protected
  27.     function GetLocale: Integer;
  28.  
  29.   public
  30.     constructor CreateParam(
  31.       owner: TComponent;
  32.       dictionary: TIvDictionary;
  33.       const msg: String;
  34.       options: TIvLanguageDialogOptions;
  35.       helpContext: THelpContext);
  36.  
  37.     property Locale: Integer read GetLocale;
  38.   end;
  39.  
  40.   function SelectLocale(
  41.     parent: TControl;
  42.     dictionary: TIvDictionary;
  43.     const msg: String;
  44.     options: TIvLanguageDialogOptions;
  45.     helpContext: THelpContext;
  46.     var locale: Integer): Boolean;
  47.  
  48. implementation
  49.  
  50. {$R *.DFM}
  51.  
  52. function SelectLocale(
  53.   parent: TControl;
  54.   dictionary: TIvDictionary;
  55.   const msg: String;
  56.   options: TIvLanguageDialogOptions;
  57.   helpContext: THelpContext;
  58.   var locale: Integer): Boolean;
  59. var
  60.   dialog: TIvLocaleSelectDialog;
  61. begin
  62.   if not dictionary.IsOpen then
  63.     raise EIvMulti.Create(
  64.       'Dictionary is not open' +
  65.       #10#13'You must open the dictionary before you can change the locale');
  66.  
  67.   Result := False;
  68.   dialog := TIvLocaleSelectDialog.CreateParam(
  69.     nil,
  70.     dictionary,
  71.     msg,
  72.     options,
  73.     helpContext);
  74.  
  75.   if not (ivloNoCenter in options) then
  76.     IvCenterControl(parent, dialog);
  77.  
  78.   if dialog.ShowModal = mrOk then
  79.   begin
  80.     locale := dialog.Locale;
  81.     Result := True;
  82.   end;
  83.   dialog.Free;
  84. end;
  85.  
  86. constructor TIvLocaleSelectDialog.CreateParam(
  87.   owner: TComponent;
  88.   dictionary: TIvDictionary;
  89.   const msg: String;
  90.   options: TIvLanguageDialogOptions;
  91.   helpContext: THelpContext);
  92. var
  93.   i: Integer;
  94.   str: String;
  95.   locale: TIvLocale;
  96.   locales: TList;
  97. begin
  98.   inherited Create(owner);
  99.  
  100.   if msg <> '' then
  101.     Caption := msg;
  102.  
  103.   Screen.Cursor := crHourglass;
  104.   Self.HelpContext := helpContext;
  105.  
  106.   { Gets the sub language ids }
  107.  
  108.   locales := TList.Create;
  109.   dictionary.GetLocales(locales);
  110.  
  111.   for i := 0 to locales.Count - 1 do
  112.   begin
  113.     locale := TIvLocale(locales[i]);
  114.  
  115. {$IFDEF WIN32}
  116.     if (not (ivloShowAllLanguages in options)) and
  117.       ((dictionary.CheckLevel = ivclCodePage) and
  118.        (not dictionary.IsLocaleSupportedByCodePage(locale))) or
  119.       ((dictionary.CheckLevel = ivclSystem) and
  120.        (not IvIsCodePageSupportedBySystem(locale.CodePage))) then
  121.     begin
  122.       Continue;
  123.     end;
  124. {$ENDIF}
  125.  
  126.     if ivloUseNativeLanguage in options then
  127.       str := locale.GetDisplayName(ivdnNative, dictionary)
  128.     else
  129.       str := locale.GetDisplayName(ivdnTranslated, dictionary);
  130.  
  131.     ListBox.Items.AddObject(str, TObject(locale.Locale));
  132.   end;
  133.  
  134.   dictionary.FreeList(locales);
  135.  
  136.   Translator.Dictionary := dictionary;
  137.   Translator.Translate;
  138.  
  139.   for i := 0 to listBox.Items.Count - 1 do
  140.   begin
  141.     if dictionary.Locale = Integer(listBox.Items.Objects[i]) then
  142.     begin
  143.       ListBox.ItemIndex := i;
  144.       Break;
  145.     end;
  146.   end;
  147.  
  148.   Screen.Cursor := crDefault;
  149. end;
  150.  
  151. function TIvLocaleSelectDialog.GetLocale: Integer;
  152. begin
  153.   Result := Integer(ListBox.Items.Objects[ListBox.ItemIndex]);
  154. end;
  155.  
  156. procedure TIvLocaleSelectDialog.ListBoxDblClick(Sender: TObject);
  157. begin
  158.   Close;
  159.   ModalResult := idOK;
  160. end;
  161.  
  162. procedure TIvLocaleSelectDialog.HelpButtonClick(Sender: TObject);
  163. begin
  164.   Application.HelpContext(HelpContext);
  165. end;
  166.  
  167. end.
  168.